<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use Notifiable;
    use SoftDeletes;
    use HasRoles;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    protected $dates = [
        'deleted_at'
    ];

    protected $attributes = [
        'menuroles' => 'user',
    ];

    public function setPasswordAttribute($v)
    {
        $this->attributes['password'] = bcrypt($v);
    }

    public function carts()
    {
        return $this->hasMany('App\Models\Cart', 'user_id');
    }

    public function addresses() {
        return $this->hasMany(Address::class, 'user_id');
    }

    public function collections()
    {
        return $this->hasMany(Collection::class, 'user_id');
    }

    public function orders()
    {
        return $this->hasMany(Order::class);
    }

    public function comments() {
        return $this->hasMany(Comment::class, 'user_id');
    }

    // protected static function boot() {
    //     parent::boot();
    //     static::updating(function($user) {
    //         dump($user);
    //         exit;
    //     });
    // }
}
